from .models import User
import secrets

def getRequestUser(request) -> User:
    """从request中获取user"""
    user_id = request.session['user_id']
    return User.objects.get(id=user_id)

def getProductAppearance() -> dict:
    """获取随机的商品名"""
    appearance = []
    for i in range(4):
        item = []
        for j in range(4):
            color = '#' + secrets.token_hex(3).upper()
            item.append(color)
        appearance.append(item)

    return {'colors': appearance}